﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using EntityBinder;
using EntityBinder.Attribute;
using EntityBinder.Binder;
using EntityBinder.Interface;
using EntityBinder.Transformer;

namespace UnitTest.Model
{
	[Entity(Identifier="ObjectContainer")]
	class ObjectContainer
	{
		[DataEntity(Identifier="object")]
		public SimpleContainer m_simple = null;


		#region test set

		public static ObjectContainer TestData1()
		{
			return new ObjectContainer()
			{
				m_simple = new SimpleContainer()
				{
					m_bool = true,
					m_char = 'p',
					m_double = 51.42,
					m_float = 69.73f,
					m_int = 4242,
					m_long = 12345,
					m_str = "hello"
				}
			};
		}

		public static ObjectContainer TestData2()
		{
			return new ObjectContainer()
			{
				m_simple = new SimpleContainer()
				{
					m_bool = false,
					m_char = 'o',
					m_double = 51.87,
					m_float = 61.73f,
					m_int = 422,
					m_long = 145,
					m_str = "world"
				}
			};
		}

		#endregion

		public static IEntityElement GetRules()
		{
			IEntityElement root = new EntityElement("ObjectContainer", new ObjectBinder<ObjectContainer>(), null);
			IEntityElement simple = new EntityElement("object", new ObjectBinder<SimpleContainer>(), MemberAccessFactory.FromType<ObjectContainer>("m_simple"));

			simple.AddChildren(
				new EntityElement("my_bool", new ContentBinder(new BoolTransformer()), MemberAccessFactory.FromType<SimpleContainer>("m_bool")),
				new EntityElement("my_char", new ContentBinder(new CharTransformer()), MemberAccessFactory.FromType<SimpleContainer>("m_char")),
				new EntityElement("my_double", new ContentBinder(new DoubleTransformer()), MemberAccessFactory.FromType<SimpleContainer>("m_double")),
				new EntityElement("my_float", new ContentBinder(new FloatTransformer()), MemberAccessFactory.FromType<SimpleContainer>("m_float")),
				new EntityElement("my_int", new ContentBinder(new IntTransformer()), MemberAccessFactory.FromType<SimpleContainer>("m_int")),
				new EntityElement("my_long", new ContentBinder(new LongTransformer()), MemberAccessFactory.FromType<SimpleContainer>("m_long")),
				new EntityElement("my_str", new ContentBinder(new StringTransformer()), MemberAccessFactory.FromType<SimpleContainer>("m_str"))
			);
			root.AddChild(simple);
			return root;
		}
	}
}
